<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>交路管理</title>
    <%@include file="../../public/commonCss.jsp" %>
    <link href="${ctx}/static/css/acss/model_jl.css" rel="stylesheet" type="text/css"/>
    <%@include file="../../public/commonJs.jsp" %>
</head>
<body ms-controller="main" class="ms-controller">
<div id="wrapper">
    <div class="boxmain whiteBox lrbox">
        <div class="from-header borderB contentbox layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <span class="font14"> 所属分类:</span><a id="category"><span class=" fontOrange2">人员派班</span></a>
                </div>
            </div>
            <div class="fr">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="radio" value="1" name="num" lay-filter='r1' title="武汉"
                               <c:if test="${num eq 1}">checked</c:if> />
                        <input type="radio" value="0" name="num" lay-filter='r1' title="汉口"
                               <c:if test="${num eq 0}">checked</c:if>/>
                        <input type="radio" value="" name="num" lay-filter='r1' title="全部"
                               <c:if test="${empty num}">checked</c:if>/>
                        <input type="checkbox" name="tempTrain" lay-filter='r2' title="查看临客"
                               <c:if test="${tempTrain=='1'}">checked</c:if>/>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="inputText" size="35" placeholder="搜索交路,车次"
                               ms-duplex="searchKey"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button class="layui-btn layui-btn-normal layui-btn-small"
                                ms-on-click="loadSearchData()">搜索
                        </button>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button class="layui-btn layui-btn-small" onclick="addLayer()">新增交路</button>
                    </div>
                </div>
            </div>

        </div>
        <div class="from-body withheader contentbox" style=" overflow: auto;">
            <table class="layui-table">
                <thead>
                <tr>
                    <th width="50" align="center">行号</th>
                    <th width="150" align="center">交路</th>
                    <th>车次</th>
                </tr>
                </thead>
                <tbody style="font-size:12px;">
                <tr ms-repeat="tableDatas">
                    <td align="center">{{$index+1}}</td>
                    <td align="center" style="position:relative;">
                        {{el.tName}}
                        <div style="position:absolute;right:5px;top:15px;">
                            <a href="javascript:;" class="jlrowedit" ms-on-click="editLayer(el)" title="编辑交路"></a>
                            <a href="javascript:;" class="jlrowdel" ms-on-click="deleteRoad(el)" title="删除交路"></a>
                        </div>
                    </td>
                    <td style="padding-bottom: 0px;">
                        <div class="jlArea">
                            <div class="jlButton" style="width:120px;" ms-repeat-tl="el.trains">
                                <table class="layui-table" lay-skin="nob">
                                    <tr align="center">
                                        <td><span style="margin-right:5px;color: #999;">{{$index+1}}</span></td>
                                        <td align="right">
                                            <span>
                                                <a href="javascript:;" class="jlrowedit"
                                                   ms-on-click="editTrain(tl.id)"></a>
                                                <a href="javascript:;" class="jlrowdel"
                                                   ms-on-click="deleteTrain(tl.id)"></a>
                                            </span>
                                        </td>
                                    </tr>
                                    <tr align="center">
                                        <td colspan="2"><span style="color: #4287cf;">{{tl.code}}</span></td>
                                    </tr>
                                    <tr align="center">
                                        <td colspan="2">{{tl.startCity}}~<span
                                                style="color: #999;">{{tl.startTime}}</span></td>
                                    </tr>
                                    <tr align="center">
                                        <td colspan="2">{{tl.endCity}}~<span
                                                style="color: #999;">{{tl.endTime}}</span></td>
                                    </tr>
                                </table>
                            </div>
                            <a href="javascript:;" class="jlrowadd" ms-on-click="addTrain(el)"></a>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <!-- whitebox -->
</div>
<script type="text/javascript">
    var vm;
    var index;
    $(function () {
        vm = avalon.define({
            $id: "main",
            treeDatas: [],//总数据
            tableDatas: [],
            roadId: '',
            searchKey: '',
            searchKey1: '',
            num: '',
            tempTrain: ''//0表示不查看临客
        });
        loadTableData();
    });

    //新增交路
    function addLayer() {
        index = layer.open({
            type: 2,
            title: '新增交路',
            area: ['600px', '600px'],
            fix: false, //不固定
            maxmin: false,
            content: '${ctx}/roadController/toRoadForm.action'
        });
    }

    //编辑交路
    function editLayer(el) {
        index = layer.open({
            type: 2,
            title: '编辑交路',
            area: ['600px', '600px'],
            fix: false, //不固定
            maxmin: false,
            content: '${ctx}/roadController/toRoadForm.action?id=' + el.id
        });
    }

    //删除
    function deleteRoad(el) {
        layerUtil.confirm("你确定删除该交路吗?", function () {
            ajaxUtil.post('${ctx}/roadController/deleteRoad.action?id=' + el.id, "", false, function (data) {
                loadTableData();
            })
        })
    }

    /**
     * 删除车次
     */
    function deleteTrain(trainId) {
        layerUtil.confirm("你确定移除该车次吗?", function () {
            ajaxUtil.post('${ctx}/roadController/removeTrainForRoad.action?id=' + trainId, "", false, function (data) {
                layerUtil.success("移除成功");
                loadTableData();
            })
        })
    }

    //新增车次
    function addTrain(el) {
        layer.open({
            type: 2,
            title: "新增车次",
            area: ['800px', '500px'],
            fix: false, //不固定
            maxmin: false,
            content: "${ctx}/roadController/toRoadTrainList.action?roadId=" + el.$model.id
        });
    }

    //编辑车次
    function editTrain(id) {
        var tabname = "编辑车次";
        var text = "编辑车次";
        var opentype = "0";
        var href = "${ctx}/trainController/toTrainForm.action?id=" + id;
        top.maincontab.opentabs(href, text, opentype, tabname);
    }

    //搜索
    function loadSearchData() {
        vm.roadId = "";
        loadTableData();
    }


    //加载菜单数据
    function loadTableData() {
        var dataStr = {
            roadId: vm.$model.roadId,
            searchKey: vm.$model.searchKey,
            num: vm.$model.num,
            tempTrain: vm.$model.tempTrain
        }
        ajaxUtil.post("${ctx}/roadController/selectAllRoad.action", dataStr, true, function (data) {
            vm.tableDatas = data.datas;
        });
    }

    var form = layui.form();
    form.on('radio(r1)', function (data) {
        if (vm.$model.num != data.value) {
            vm.num = data.value;
            loadTableData();
        }
    });
    form.on('checkbox(r2)', function (data) {
        if (data.elem.checked) {
            vm.tempTrain = '1';
        } else {
            vm.tempTrain = '';
        }
        loadTableData();
    });
    //监听提交
    form.render();
</script>
</body>
</html>